import 'dart:convert';

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:graphic/graphic.dart';
import 'package:top_foundation/component/page_state/widgets/empty.dart';
import 'package:whale/helper/component/component.dart';
import 'package:whale/helper/utils/util.dart';
import '../index.dart';

class TypeDataView extends GetView<WatchController> {
  const TypeDataView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    int maxValue = 0;
    controller.state.typeDatas!.forEach((element) {
      if ((element.problemTypeSum ?? 0) > maxValue) {
        maxValue = element.problemTypeSum!.toInt();
      }
    });


    int singleMaxY = (maxValue / 5).ceil();

    return Container(
      width: 1.sw,

      margin: EdgeInsets.only(top: 15.r),
      padding: EdgeInsets.only(bottom: 10.r),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.symmetric(vertical: 15.r),
            child: Text(
              '违规类型分析',
              style: TextStyle(
                color: ColorsUtil.title,
                fontSize: 16.sp,
                fontWeight: FontWeight.bold
              ),
            ),
          ),
          Container(
            width: 1.sw,
            padding: EdgeInsets.all(15.r),

            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(2.r),
            ),
            child: singleMaxY>0?Stack(
              alignment: Alignment.bottomCenter,
              children: [
                SizedBox(
                  height: 185.r,
                  child: Row(
                    children: [
                      SizedBox(
                        width: 10.r,
                      ),
                      Expanded(
                          child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffECF0F5),
                          ),
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffECF0F5),
                          ),
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffECF0F5),
                          ),
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffECF0F5),
                          ),
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffECF0F5),
                          ),
                          Divider(
                            height: 0.5,
                            thickness: 0.5,
                            color: Color(0xffBAC7D0),
                          ),
                        ],
                      ))
                    ],
                  ),
                ),
                controller.state.typeDatas!.isEmpty
                    ? const SizedBox()
                    : Container(

                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [

                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            width: 65.r,
                            height: 70.r,
                            margin: EdgeInsets.only(bottom: 5.r),
                            padding: EdgeInsets.all(5.r),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                      color: Color(0xff123988).withOpacity(0.16),
                                      offset: Offset(0, 2), //阴影y轴偏移量
                                      blurRadius: 4, //阴影模糊程度
                                      spreadRadius: 0.4 //阴影扩散程度
                                  ),
                                ]
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '${controller.state.typeDatas![0].problemTypeSum!.toInt()}',
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 18.r,fontWeight: FontWeight.bold),
                                ),
                                SizedBox(height: 7.r,),
                                Text(
                                  '${controller.state.typeDatas![0].problemType}',
                                  textAlign: TextAlign.center,
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 9.r),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                colors: [Color(0xFF2FA4FF), Color(0xFF66A6FF)],
                                begin: Alignment.centerLeft,
                                end: Alignment.centerRight,
                              ),
                            ),
                            height: 185.r *
                                controller
                                    .state.typeDatas![0].problemTypeSum!
                                    .toInt() /
                                (singleMaxY * 5),
                            width: 23.r,
                          )
                        ],
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            width: 65.r,
                            height: 70.r,
                            margin: EdgeInsets.only(bottom: 5.r),
                            padding: EdgeInsets.all(5.r),
                            decoration: BoxDecoration(
                              color: Colors.white,
                              boxShadow: [
                                BoxShadow(
                                    color: Color(0xff123988).withOpacity(0.16),
                                    offset: Offset(0, 2), //阴影y轴偏移量
                                    blurRadius: 4, //阴影模糊程度
                                    spreadRadius: 0.4 //阴影扩散程度
                                ),
                              ]
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '${controller.state.typeDatas![1].problemTypeSum!.toInt()}',
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 18.r,fontWeight: FontWeight.bold),
                                ),
                                SizedBox(height: 7.r,),
                                Text(
                                  '${controller.state.typeDatas![1].problemType}',
                                  textAlign: TextAlign.center,
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 9.r),
                                ),
                              ],
                            ),
                          ),
                          Container(
                           decoration: BoxDecoration(
                             gradient: const LinearGradient(
                               colors: [Color(0xFF2FA4FF), Color(0x4066A6FF)],
                               begin: Alignment.topCenter,
                               end: Alignment.bottomCenter,
                             ),
                             borderRadius: BorderRadius.vertical(top: Radius.circular(2.r)),
                             // border: Border.all(color: Color(0xff007EFF))

                           ),
                            height: 185.r *
                                controller
                                    .state.typeDatas![1].problemTypeSum!
                                    .toInt() /
                                (singleMaxY * 5),
                            width: 23.r,

                          )
                        ],
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            width: 65.r,
                            height: 70.r,
                            margin: EdgeInsets.only(bottom: 5.r),
                            padding: EdgeInsets.all(5.r),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                      color: Color(0xff123988).withOpacity(0.16),
                                      offset: Offset(0, 2), //阴影y轴偏移量
                                      blurRadius: 4, //阴影模糊程度
                                      spreadRadius: 0.4 //阴影扩散程度
                                  ),
                                ]
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '${controller.state.typeDatas![2].problemTypeSum!.toInt()}',
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 18.r,fontWeight: FontWeight.bold),
                                ),
                                SizedBox(height: 7.r,),
                                Text(
                                  '${controller.state.typeDatas![2].problemType}',
                                  textAlign: TextAlign.center,
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 9.r),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                colors: [Color(0xFF2FA4FF), Color(0x4066A6FF)],
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                              ),
                              borderRadius: BorderRadius.vertical(top: Radius.circular(2.r)),
                              // border: Border.all(color: Color(0xff007EFF))
                            ),
                            height: 185.r *
                                controller
                                    .state.typeDatas![2].problemTypeSum!
                                    .toInt() /
                                (singleMaxY * 5),
                            width: 23.r,
                          )
                        ],
                      ),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            width: 65.r,
                            height: 70.r,
                            margin: EdgeInsets.only(bottom: 5.r),
                            padding: EdgeInsets.all(5.r),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                      color: Color(0xff123988).withOpacity(0.16),
                                      offset: Offset(0, 2), //阴影y轴偏移量
                                      blurRadius: 4, //阴影模糊程度
                                      spreadRadius: 0.4 //阴影扩散程度
                                  ),
                                ]
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '${controller.state.typeDatas![3].problemTypeSum!.toInt()}',
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 18.r,fontWeight: FontWeight.bold),
                                ),
                                SizedBox(height: 7.r,),
                                Text(
                                  '${controller.state.typeDatas![3].problemType}',
                                  textAlign: TextAlign.center,
                                  style:
                                  TextStyle(color: ColorsUtil.title, fontSize: 9.r),
                                ),
                              ],
                            ),
                          ),
                          Container(
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                colors: [Color(0xFF2FA4FF), Color(0x4066A6FF)],
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                              ),
                              borderRadius: BorderRadius.vertical(top: Radius.circular(2.r)),
                              // border: Border.all(color: Color(0xff007EFF))

                            ),
                            height: 185.r *
                                controller
                                    .state.typeDatas![3].problemTypeSum!
                                    .toInt() /
                                (singleMaxY * 5),
                            width: 23.r,
                          )
                        ],
                      ),
                    ],
                  ),
                )
              ],
            ):noDataView(),
          ),
        ],
      ),
    );
  }
}
